<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            const SERVER_URL = 'http://localhost:3000/todos'
            const xhr = new XMLHttpRequest()
            // 创建 Http 请求
            xhr.open('GET', SERVER_URL, true)
            // 设置状态监听函数
            xhr.onreadystatechange = function () {
                if (this.readyState !== 4) return
                // 当请求成功时
                if (this.status === 200) {
                    console.log(this.response)
                } else {
                    console.error(this.statusText)
                }
            }
            // 设置请求失败时的监听函数
            xhr.onerror = function () {
                console.error(this.statusText)
            }
            // 设置请求头信息
            xhr.responseType = 'json'
            xhr.setRequestHeader('Accept', 'application/json')
            xhr.send()
        </script>
    </body>
</html>
